package com.purebang.spaceinvaders;

import java.util.LinkedList;
import java.util.List;

public class Bunker {
	public List<BunkerSection> sections;
	
	public static final int NUMBER_OF_BUNKER_COLS = 4;
	public static final int NUMBER_OF_BUNKER_ROWS = 4;
	public static final int BUNKER_WIDTH = NUMBER_OF_BUNKER_COLS * BunkerSection.BUNKER_SECTION_WIDTH;
	public static final int BUNKER_HEIGHT = NUMBER_OF_BUNKER_ROWS * BunkerSection.BUNKER_SECTION_HEIGHT;
	
	private final int NUMBER_OF_SECTIONS = 12;
	//Top of bunker
	private final int NUMBER_OF_TOP_SECTIONS = 8;
	private final int NUMBER_OF_TOP_COLUMNS = 4;
	//Bottom of bunker
	private final int NUMBER_OF_BOTTOM_SECTIONS = 4;
	private final int NUMBER_OF_BOTTOM_COLUMNS = 2;
	
	private final int BOTTOM_SECTION_SPACING = 3 * BunkerSection.BUNKER_SECTION_WIDTH;
	
	public Bunker(int x, int y) {
		int colCarriage = 0;
		sections = new LinkedList<BunkerSection>();
		for (int i = 1; i <= NUMBER_OF_SECTIONS; i++) {
			if(i <= NUMBER_OF_TOP_SECTIONS) {
				BunkerSection section = new BunkerSection(x + colCarriage * BunkerSection.BUNKER_SECTION_WIDTH,
						y + ((i-1)/NUMBER_OF_TOP_COLUMNS * BunkerSection.BUNKER_SECTION_HEIGHT));
				sections.add(section);
				
				colCarriage ++;
				if(colCarriage == NUMBER_OF_TOP_COLUMNS) {
					colCarriage = 0;
				}
			}else if (i <= (NUMBER_OF_BOTTOM_SECTIONS + NUMBER_OF_TOP_SECTIONS)) {
				BunkerSection section = new BunkerSection(x + colCarriage * BOTTOM_SECTION_SPACING,
						y + ((i - 1 - NUMBER_OF_TOP_COLUMNS) / NUMBER_OF_BOTTOM_COLUMNS * 
						BunkerSection.BUNKER_SECTION_HEIGHT));
				sections.add(section);
				
				colCarriage ++;
				if(colCarriage == NUMBER_OF_BOTTOM_COLUMNS) {
					colCarriage = 0;
				}
			}
		}
	}
	

}
